package com.js.myapp.common.centercrop;

import android.content.Context;
import android.graphics.Bitmap;

import androidx.annotation.NonNull;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.js.basicutils.BlurBitmapUtil;

import java.security.MessageDigest;

/**
 * 高斯模糊
 */
public class GlideBlurTransformation extends CenterCrop {
    private Context context;
    private float blurRadius;

    /**
     *
     * @param context 上下文
     * @param blurRadius 模糊程度，数值范围在 1-25之间，数值越大越模糊
     */
    public GlideBlurTransformation(Context context, float blurRadius) {
        this.context = context;
        this.blurRadius = blurRadius;
    }

    @Override
    protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
        // 设置渲染的模糊程度, 25f是最大模糊度
        return BlurBitmapUtil.instance().blurBitmap(context, toTransform, blurRadius, outWidth, outHeight);
    }

    @Override
    public void updateDiskCacheKey(MessageDigest messageDigest) {
    }

}